package com.xiaodu.dynamicdatasource;

import com.xiaodu.dynamicdatasource.entity.UserEntity;
import com.xiaodu.dynamicdatasource.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author: dutianjie
 * @date: 2021/4/22
 * @version: v1.0.0
 * @description: 描述
 **/
@SpringBootApplication
public class StartApplication implements CommandLineRunner {

    @Autowired
    UserMapper userMapper;


    public static void main(String[] args) {
        SpringApplication.run(StartApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        // 切换数据源
//        DataSourceContextHolder.setDataSourceKey("pgDataSource");
        UserEntity oneById = userMapper.getOneById("022ef6bebdf841ba9c0519ac5b5c0542");
        System.out.println(oneById);
//        DataSourceContextHolder.removeDataSourceKey();
    }
}
